/**
 * 
 */
package pl.kane.autokomp.applications.actionlisteners.run;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.text.DateFormat;
import java.util.Date;

import pl.kane.autokomp.applications.MainFrame;
import pl.kane.autokomp.livegenerator.Generator;

/**
 * @author Lukasz Wator
 *
 */
public class RunAction implements ActionListener {
	 public void actionPerformed(ActionEvent arg0) {
		 final MainFrame mainFrame = MainFrame.getInstance() ;
		 Generator generator = new Generator();
		 try {
			mainFrame.hideWindow();
			Date now = new Date();
			mainFrame.addToConsole("File "+mainFrame.getCurrentFileName()+" run start time: "+ DateFormat.getTimeInstance().format(now)+"\n");
			generator.run(mainFrame.getCode());
			mainFrame.showWindow(); 
			now = new Date();
			mainFrame.addToConsole("File "+mainFrame.getCurrentFileName()+" run end time:" + DateFormat.getTimeInstance().format(now)+"\n");
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (InstantiationException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (ClassNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
     }

}
